#!/bin/bash
#!/bin/ksh
cd /users/moliaipu/documents/MolyAppAKey/
#create plist file
cat << EOF > MolyAppAKey-Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>items</key>
   <array>
       <dict>
           <key>assets</key>
           <array>
               <dict>
                   <key>kind</key>
                   <string>software-package</string>
                   <key>url</key>
                   <string>http://domain/app.ipa</string>
               </dict>
               <dict>
                   <key>kind</key>
                   <string>display-image</string>
                   <key>needs-shine</key>
                   <true/>
                   # <key>url</key>
                   # <string>http://domain/logo/logo.png</string>
               </dict>
           </array>
           <key>metadata</key>
           <dict>
               <key>bundle-identifier</key>
               <string>domain</string>
               <key>bundle-version</key>
               <string>1.0.0</string>
               <key>kind</key>
               <string>software</string>
               <key>subtitle</key>
               <string>App Subtitle</string>
               <key>title</key>
               <string>App Title</string>
           </dict>
       </dict>
   </array>
</dict>
</plist>


EOF

#set pilst file
cp -f /users/moliaipu/documents/MolyAppAKey/MolyAppAKey-Info.plist /users/moliaipu/documents/MolyAppAKey/MolyAppAKey/MolyAppAKey-Info.plist

#clean
/usr/bin/xcodebuild -target MolyAppAKey clean

#build
/usr/bin/xcodebuild -target MolyAppAKey CODE_SIGN_IDENTITY=“D374S29BEC”

#unlock keychain

security create-keychain  -p "123456" ~/Library/Keychains/login.keychain
security unlock-keychain  -p "123456" ~/Library/Keychains/login.keychain
security unlock-keychain  -p “123456” /Users/moliaipu/Library/Keychains/login.keychain

#package
#build路径找不到
xcrun -sdk iphoneos PackageApplication -v Build/Release-iphoneos/MolyAppAKey.app -o /users/moliaipu/documents/MolyAppAKey/output/MolyAppAKey.ipa --sign 324092820BBB281F3B022978FA7FFF8F28A3A66D  --embed Build/Release-iphoneos/MolyAppAKey.app /embed.mobileprovision
#delete
security delete-keychain “123456” /Users/moliaipu/Library/Keychains/login.keychain


